package cfg

import (
	"gitee.com/ruige_fun/util/rlog"
	"os"
	"path"
	"runtime"
	"strings"
)

const (
	FILEPATH         = "./files"
	LogDir           = FILEPATH + "/log"
	ConfigDir        = FILEPATH + "/config"
	UploadDir        = FILEPATH + "/upload"
	DownloadDir      = FILEPATH + "/download"
	DefaultFileModel = 0660
)

var ProjectPath = "" //项目所在文件路径
var BuildTime = ""

func init() {
	_, file, _, _ := runtime.Caller(0)
	ProjectPath = strings.ReplaceAll(file, "cfg/init.go", "")

	autoMkdir()

	readConfig()

	rlog.SetLogFilePath(path.Join(LogDir, "app.log"))
	rlog.SetOldLogZip(true)
	rlog.SetLogMaxSize(1024 * 1024 * 100)
	rlog.SetCodePathEllipsisLength(len(ProjectPath))
}

// autoMkdir 自动创建文件夹
func autoMkdir() {
	_ = os.MkdirAll(LogDir, DefaultFileModel)
	_ = os.MkdirAll(ConfigDir, DefaultFileModel)
	_ = os.MkdirAll(UploadDir, DefaultFileModel)
	_ = os.MkdirAll(DownloadDir, DefaultFileModel)
}
